// pages/order/list/index.js
import {
  request
} from '../../utils/requestUtils';
Page({
  // 页面的初始数据
  data: {
    refreshTriggered: false,
    total: 0,
    page: {
      pageNum: 1,
      pageSize: 10,
    },
    params: {
      orderStatus:'4',
      keywords: ''
    },
    orderList: []
  },
  onLoad() {
    // this.getList()
  },
  onShow() {
    this.getTabBar().setData({
      active: 0
    })
    this.onScrollRefresh()
  },
  // 切换订单状态
  statusChange(event){
    this.setData({
      'params.orderStatus':event.detail.name
    })
    console.log(this.data.params.orderStatus)
    this.onScrollRefresh()
  },
  // 触底刷新
  getNext() {
    if (this.data.page.pageNum * this.data.page.pageSize >= this.data.total) {
      return
    } else {
      this.data.page.pageNum++;
      this.getMerchantList();
    }
    this.getList()
  },
  // 下拉刷新
  onScrollRefresh: function () {
    this.setData({
      'page.pageNum': 1,
       orderList:[]
    })
    this.getList()

  },
  // 查询商品信息
  async getList() {
    const result = await request({
      url: `/api/bus/groupRiderOrder/list?pageNum=${this.data.page.pageNum}&pageSize=${this.data.page.pageSize}`,
      method: "POST",
      data: {
        name: this.data.params.keywords,
        params: {
          keywords: this.data.params.keywords,
          orderStatus: this.data.params.orderStatus
        }
      }
    })
    this.setData({
      refreshTriggered: false
    })
    if (result.data.code == 200) {
      var orderList = this.data.orderList.concat(result.data.rows)
      console.log('orderList', orderList)
      this.setData({
        orderList: orderList,
        total: result.data.total
      })
    }
  },
  // 跳转订单详情
  toDetails(event){
    console.log('event', event)
    const {id,type} = event.currentTarget.dataset
    if (event.target.id === 'child') return
    if(type == 1){
      wx.navigateTo({
        url: '/pages/rider_order_details/index?id='+id
      })
    }else{
      wx.navigateTo({
        url: '/pages/rider_return_order_detail/index?id='+id
      })
    }
    
  }
})